#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <fmt/format.h>
using namespace std;

// filestream include ifstream and ofstream for file content operation

void writeToFile()
{
    if (std::ofstream output{"client.txt", std::ios::out})
    {
#ifdef _WIN32
        std::cout << "Enter the account,name,and balance.\n"
                  << "Enter end-of-file(Control+Z) + Enter to end input.\n? ";
#else

        std::cout << "Enter the account,name,and balance.\n"
                  << "Enter end-of-file(Control+D) to end input.\n? ";
#endif
        int account;
        std::string name;
        double balance;
        // while (std::cin >> account >> name >> balance)
        // import '<iomanip>' for std::quoted
        while (std::cin >> account >> std::quoted(name) >> balance)
        {
            output << fmt::format("{} {} {}\n", account, name, balance);
            std::cout << "? ";
        }
    }
    else
    {
        std::cerr << "File could not be opened!\n";
        std::exit(EXIT_FAILURE);
    }
}

void readFromFile()
{
    if (std::fstream input{"clients.txt", std::ios::in})
    {
        std::cout << fmt::format("{:<10}{:<13}{:>7}\n", "Account", "Name", "Balance");
        int account;
        std::string name;
        double balance;

        while (input >> account >> name >> balance)
        {
            std::cout << fmt::format("{:<10}{:<13}{:>7.2f}\n", account, name, balance);
        }
    }
    else
    {
        std::cerr << "File could not be opened!\n";
        std::exit(EXIT_FAILURE);
    }
}

int main()
{
    readFromFile();
    return 0;
}
